const TokenKey = 'token'
const UserKey = 'userInfo'
const ServiceKey = 'serviceInfo'

/**
 * 获取token
 * @returns {string}
 */
export function getToken() {
    return uni.getStorageSync(TokenKey)
}

/**
 * 设置token
 * @param {string} token
 */
export function setToken(token) {
    return uni.setStorageSync(TokenKey, token)
}

/**
 * 移除token
 */
export function removeToken() {
    return uni.removeStorageSync(TokenKey)
}

/**
 * 获取用户信息
 * @returns {Object}
 */
export function getUserInfo() {
    return uni.getStorageSync(UserKey)
}

/**
 * 设置用户信息
 * @param {Object} userInfo
 */
export function setUserInfo(userInfo) {
    return uni.setStorageSync(UserKey, userInfo)
}

/**
 * 移除用户信息
 */
export function removeUserInfo() {
    return uni.removeStorageSync(UserKey)
}

/**
 * 获取客服信息
 * @returns {Object}
 */
export function getServiceInfo() {
    return uni.getStorageSync(ServiceKey)
}

/**
 * 设置客服信息
 * @param {Object} serviceInfo
 */
export function setServiceInfo(serviceInfo) {
    return uni.setStorageSync(ServiceKey, serviceInfo)
}

/**
 * 移除客服信息
 */
export function removeServiceInfo() {
    return uni.removeStorageSync(ServiceKey)
}

/**
 * 清除所有认证信息
 */
export function clearAuth() {
    removeToken()
    removeUserInfo()
    removeServiceInfo()
}

/**
 * 检查是否已登录
 * @returns {boolean}
 */
export function isLoggedIn() {
    return !!getToken()
}

/**
 * 检查是否是客服
 * @returns {boolean}
 */
export function isCustomerService() {
    const userInfo = getUserInfo()
    return userInfo && userInfo.roles && userInfo.roles.includes('ROLE_CUSTOMER_SERVICE')
}

/**
 * 检查是否是管理员
 * @returns {boolean}
 */
export function isAdmin() {
    const userInfo = getUserInfo()
    return userInfo && userInfo.roles && userInfo.roles.includes('ROLE_ADMIN')
} 